// Copyright (c) 2009 Luca Marrocco.
// Modified or written by Luca Marrocco for inclusion with codej.
// Licensed under the Apache License, Version 2.0 (the "License")
package codej.ast;


/** @author Luca Marrocco */
public class FormalParameter extends AbstractNode {

	private boolean isFinal = false;
	private Type type;
	private int dimension;
	private String name;

	public FormalParameter() {
	}

	public void accept(Visitor visitor) {
		visitor.visit((FormalParameter) this);
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null)
			return false;
		if (!(obj instanceof FormalParameter))
			return false;

		FormalParameter anotherFormalParameter = (FormalParameter) obj;
		return toString().equals(anotherFormalParameter.toString());
	}

	public int getDimension() {
		return dimension;
	}

	public boolean getFinal() {
		return isFinal;
	}

	public String getName() {
		return name;
	}

	public Type getType() {
		return type;
	}

	public boolean isFinal() {
		return isFinal;
	}

	public FormalParameter setDimension(int dimension) {
		this.dimension = dimension;
		return this;
	}

	public FormalParameter setFinal(boolean isFinal) {
		this.isFinal = isFinal;

		return this;
	}

	public FormalParameter setName(String name) {
		this.name = name;
		return this;
	}

	public FormalParameter setType(Type type) {
		this.type = type;

		return this;
	}

	public String toString() {
		StringBuffer stringBuffer = new StringBuffer();
		stringBuffer.append(type.getName());
		if (1 == getDimension())
			stringBuffer.append("[]");
		if (2 == getDimension())
			stringBuffer.append("[][]");
		if (3 == getDimension())
			stringBuffer.append("[][][]");
		stringBuffer.append(" ");
		stringBuffer.append(getName());

		return stringBuffer.toString();
	}

	public void setAnnotations(Annotations annotations) {
		addChild(annotations);
	}
}